package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HaDrugStocks;
import com.ruoyi.system.service.IHaDrugStocksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实时库存Controller
 * 
 * @author 鲍小伟
 * @date 2025-11-26
 */
@RestController
@RequestMapping("/system/stocks")
public class HaDrugStocksController extends BaseController
{
    @Autowired
    private IHaDrugStocksService haDrugStocksService;

    /**
     * 查询实时库存列表
     */
    @PreAuthorize("@ss.hasPermi('system:stocks:list')")
    @GetMapping("/list")
    public TableDataInfo list(HaDrugStocks haDrugStocks)
    {
        startPage();
        List<HaDrugStocks> list = haDrugStocksService.selectHaDrugStocksList(haDrugStocks);
        return getDataTable(list);
    }

    /**
     * 导出实时库存列表
     */
    @PreAuthorize("@ss.hasPermi('system:stocks:export')")
    @Log(title = "实时库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HaDrugStocks haDrugStocks)
    {
        List<HaDrugStocks> list = haDrugStocksService.selectHaDrugStocksList(haDrugStocks);
        ExcelUtil<HaDrugStocks> util = new ExcelUtil<HaDrugStocks>(HaDrugStocks.class);
        util.exportExcel(response, list, "实时库存数据");
    }

    /**
     * 获取实时库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:stocks:query')")
    @GetMapping(value = "/{stockid}")
    public AjaxResult getInfo(@PathVariable("stockid") Long stockid)
    {
        return success(haDrugStocksService.selectHaDrugStocksByStockid(stockid));
    }

    /**
     * 新增实时库存
     */
    @PreAuthorize("@ss.hasPermi('system:stocks:add')")
    @Log(title = "实时库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HaDrugStocks haDrugStocks)
    {
        return toAjax(haDrugStocksService.insertHaDrugStocks(haDrugStocks));
    }

    /**
     * 修改实时库存
     */
    @PreAuthorize("@ss.hasPermi('system:stocks:edit')")
    @Log(title = "实时库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HaDrugStocks haDrugStocks)
    {
        return toAjax(haDrugStocksService.updateHaDrugStocks(haDrugStocks));
    }

    /**
     * 删除实时库存
     */
    @PreAuthorize("@ss.hasPermi('system:stocks:remove')")
    @Log(title = "实时库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{stockids}")
    public AjaxResult remove(@PathVariable Long[] stockids)
    {
        return toAjax(haDrugStocksService.deleteHaDrugStocksByStockids(stockids));
    }
}
